import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/denglu',
      name: 'denglu',
      component: () => import('../views/Denglu.vue')
    },
    {
      path: '/',
      name: 'home',
      component: HomeView,
      children:[
        {
          path: '/',
          name: 'shouye',
          component: () => import('../views/Shouye.vue')
        },
        {
        path: '/music',
        name: 'music',
        component: () => import('../views/music.vue')
      }  
      ]
    },
    {
      path: '/:catchAll(.*)',
      name: 'my404',
      component: () => import('../views/my404.vue')
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    }
  ]
})


/**
 * 前置路由守卫
 */
router.beforeEach(()=>{
  //判断是否登录
  if(toString.path==='/login'){
    next()
  }else{
    const tokenObject = localStorage.getItem("token")
    if (tokenObject) {
      next()      
    }else{
      
    }
  }

});
export default router
